package com.kcht.sylyg08.dao.impl;

import com.kcht.adp.common.log.Logger;
import com.kcht.adp.common.sql.JPAConfig;
import com.kcht.sylyg08.dao.DataSourceBaseDao;
import com.kcht.sylyg08.dao.ITaskDao;
import com.kcth.sylyg08.entity.Task;

import javax.ejb.Singleton;
import javax.ejb.Startup;
import javax.inject.Inject;
import java.util.List;

/**
  *
  * @Package:        com.kcht.sylyg08.dao.impl
  * @Description:    任务DAO实现类，封装了从数据库查询任务的相关方法
  * @Author:         lenovo
  * @CreateDate:     2019/5/15 14:09
 */
@Singleton
@Startup
@JPAConfig(dynaSqlFile = "mapper/taskQueryMapper.xml")
public class TaskDao extends DataSourceBaseDao<Task, Long> implements ITaskDao {
    @Inject
    private Logger log;

    /**
     * 获取所有任务对象
     *
     * @return 所有任务对象列表
     */
    @Override
    public List<Task> list() {
        return this.selectListByJPQL("select a from Task a");
    }

    /**
     * 获取所有未完成任务
     *
     * @return 所有未完成任务列表
     */
    @Override
    public List<Task> listTaskToDo() {
        return this.selectListBySQL("select * from t_syly_task where status=0", Task.class);
    }

    /**
     * 根据料框编号查询未完成任务
     *
     * @param containerId 料框编号
     * @return 查询结果任务
     */
    @Override
    public Task getTaskByContainerId(String containerId) {
        return this.selectOneByJPQL("select a from Task a where a.status=0 and a.containerId=?", containerId);
    }

    @Override
    public Task getTaskByTaskId(String taskId) {
        return this.selectOneByJPQL("select a from Task a where a.taskId = ?", taskId);
    }

    @Override
    public Task getOutGoingTaskByTaskId(String taskId) {
        return this.selectOneByJPQL("select a from Task a where a.taskType=2 and a.taskId = ?", taskId);
    }
}
